﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Oplaco.Web.DTO;
using Oplaco.Web.DTO.IMPL;

public partial class Controls_Admin_StatsControl : System.Web.UI.UserControl
{
    #region Property
    public bool ShowActiveAds { get; set; }
    public bool ShowTotalAds { get; set; }
    public bool ShowResponsesActiveAds { get; set; }
    public bool ShowTotalResponses { get; set; }
    public bool ShowAdsPending { get; set; }
    public bool ShowAdsDeleted { get; set; }
    public bool ShowTotalMembers { get; set; }
    public bool ShowNewRegistrations { get; set; }
    public bool ShowCategories { get; set; }
    public bool ShowLocations { get; set; }
    public String PanelLink { get; set; }
    public String PanelLinkTitle { get; set; }
    public String PanelTitle { get; set; }
    #endregion

    /// <summary>
    /// Loads all stats from database
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    /// <remarks>still to do; is localization, at least to get rid off static text</remarks>
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack) {
            StatisticsManager.Clear(Context);
            CachedStatisticsCollection statsColl = StatisticsManager.Fetch(HttpContext.Current);
            if (statsColl != null)
            {
                CachedStatistics stats = statsColl[0];

                lblActiveAds.Visible = ShowActiveAds;
                lblActiveAds.Text = "# Active ads: " + stats.ActiveAds.ToString();

                lblAdsDeleted.Visible = ShowAdsDeleted;
                lblAdsDeleted.Text = "# Pending Deleted ads: " + stats.DeletedAds.ToString();

                lblAdsPending.Visible = ShowAdsPending;
                lblAdsPending.Text = "# Pending ads: " + stats.PendingAds.ToString();

                lblCategories.Visible = ShowCategories;
                lblCategories.Text = "# Categories: " + stats.TopCategories.ToString();                                

                lblNewRegistrations.Visible = ShowNewRegistrations;
                lblNewRegistrations.Text = "# New registrations: " + stats.NewUsers.ToString();

                lblResponsesActiveAds.Visible = ShowResponsesActiveAds;
                lblResponsesActiveAds.Text = "# Responses to active ads: " + stats.ActiveAdResponses.ToString();

                lblTotalAds.Visible = ShowTotalAds;
                lblTotalAds.Text = "# Total ads: " + stats.TotalAds.ToString();

                lblTotalMembers.Visible = ShowTotalMembers;
                lblTotalMembers.Text = "# Total Members: " + stats.TotalUsers.ToString();

                lblTotalResponses.Visible = ShowTotalResponses;
                lblTotalResponses.Text = "# Of responses to ads: " + stats.TotalResponses.ToString();

                hlPanelLink.Text = PanelLinkTitle;
                hlPanelLink.NavigateUrl = PanelLink;
                hlPanelLink.Visible = true;

                lblTitle.Text = PanelTitle;
                lblTitle.Visible = true;
            }
        }
    }

    
}